package com.boomsecret.threadpool;

import java.util.concurrent.*;

/**
 * Created by wangjinliang on 2018/1/19.
 */
public class ThreadPoolTest {

    public static void main(String[] args) {
        ExecutorService threadPoolExecutor = Executors.newSingleThreadExecutor();
        for (int index = 0; index < 30; index ++) {
            threadPoolExecutor.execute(new Task(index));
        }
        threadPoolExecutor.shutdown();
    }
}

class Task implements Runnable {

    private int index;

    public Task(int index) {
        this.index = index;
    }

    @Override
    public void run() {
        System.out.println(index + "正在执行...");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
        }
        System.out.println(index + "执行结束...");
    }
}